package com.lzw.bluetoothpractice.Fragment;

import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

import androidx.fragment.app.Fragment;
import androidx.viewpager.widget.ViewPager;

import com.google.android.material.tabs.TabLayout;
import com.lzw.bluetoothpractice.Activitys.BaseActivity;
import com.lzw.bluetoothpractice.Activitys.IndexActivity;
import com.lzw.bluetoothpractice.Activitys.RecoveryScheActivity;
import com.lzw.bluetoothpractice.Adapters.TableFragmentPagerAdapter;
import com.lzw.bluetoothpractice.R;

import java.util.ArrayList;


public class PlanFragment extends Fragment  {
    View view;
    TableFragmentPagerAdapter tableFragmentPagerAdapter;
    ArrayList<Fragment> lists;
    LinearLayout iconBack;
    TextView tvtitle;
    ImageView iconSet;
    TabLayout tabLayout;
    ViewPager viewPager;
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState){
        view = inflater.inflate(R.layout.activity_recovery_plan,null);
        tabLayout = (TabLayout) view.findViewById(R.id.tl_check_title);
        viewPager= (ViewPager) view.findViewById(R.id.vp_check_container);
        iconBack=view.findViewById(R.id.navBack);
        iconSet=(ImageView)view.findViewById(R.id.navSet);
        tvtitle=view.findViewById(R.id.tvTitle);
        InitView();
        return view;
    }


    private  void InitView(){
        InitNavBar(false,"康复计划",true);

       //  viewPager.setAdapter(tableFragmentPagerAdapter);
        //关联viewPager和TabLayout
        tabLayout.setupWithViewPager(viewPager);

        tableFragmentPagerAdapter  = new TableFragmentPagerAdapter(getChildFragmentManager());

        lists= new ArrayList<Fragment>();
        lists.add(new TodayTargetFragment(getActivity()));
        lists.add(new StageTargetFragment());
        lists.add(new ThridFragment());
        tableFragmentPagerAdapter.setData(lists);

        ArrayList<String> tabs = new ArrayList<String>();
        tabs.add("术后第一阶段");
        tabs.add("术后第二阶段");
        tabs.add("术后第三阶段");
        tableFragmentPagerAdapter.setTabs(tabs);
        viewPager.setAdapter(tableFragmentPagerAdapter);

    }
    protected void InitNavBar(boolean isShowBack,String title,boolean isShowSet){


        iconBack.setVisibility(isShowBack ? View.VISIBLE : View.GONE);
        iconSet.setVisibility(isShowSet ? View.GONE : View.GONE);
        tvtitle.setText(title);
        iconSet.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                startActivity(new Intent(getActivity(), RecoveryScheActivity.class));
            }
        });




    }
}
